//登录鉴权
import { createRouter } from 'vue-router';
import { getToken } from './utils/setTokenUtils';

const router = createRouter();
const whiteList = ['/login', '/404'];

router.beforeEach((to, form, next) => {
  const token = getToken();
  if (token) {
    if (to.path === '/login') {
      next('/');
    } else {
      next();
    }
  } else {
    if (whiteList.includes(to.path)) {
      next();
    } else {
      next('/login');
    }
  }
  ``;
});

//后置守卫
router.afterEach((to, form) => {
  window.scrollTo(0, 0);
});
